/************************************************************************
 * 项目名称（软件名称）：忠旺机械物资管理系统(mms)                           *
 * 研发设计单位：忠旺机械设备制造有限公司机械设计院智能控制设计科设计与研发。   *
 * 版权所有：忠旺机械设备制造有限公司                                       *
 * 注：本项目的一切技术专利，使用规范归解释权由忠旺机械设备制造有限公司所有。   *
 * 软件版本：Ver 1.0.0                                                   *
 * 文件路径：com.zhongwang.mms.module.buy.controller                     *
 * 创建时间：2020年08月11日 18时03分                                      *
 *======================================================================*/
package com.zhongwang.mms.module.buy.controller;






import com.google.gson.*;
import com.google.gson.reflect.TypeToken;
import com.zhongwang.mms.base.BaseController;
import com.zhongwang.mms.common.JsonResult;
import com.zhongwang.mms.gen.entity.TEmploy;
import com.zhongwang.mms.gen.entity.VwDictCommon;
import com.zhongwang.mms.module.buy.model.ShopPlanChangeReceiveModel;
import com.zhongwang.mms.module.buy.service.PurchasePlanChangeManagementService;
import com.zhongwang.mms.module.purchase.service.PInventoryInfoEditService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RequestMapping("/plan/change")
@Controller
/**
 *@name: PurchasePlanChangeManagementController
 *@description: 采购计划变更管理控制层
 *@author: 徐一贺
 *@coddingDate: 2020/8/11 18:03
 *@version: v1.0
**/
public class PurchasePlanChangeManagementController extends BaseController {

    @Autowired
    private PurchasePlanChangeManagementService purchasePlanChangeManagementService;
    @Autowired
    private PInventoryInfoEditService pInventoryInfoEditService;

    @GetMapping
    /**
     *@name: page
     *@description: 跳转到采购计划变更接收页面
     *@param: []
     *@returnType: java.lang.String
     *@author: 徐一贺
     *@coddingDate: 2020/8/11 18:26
     *@version: v1.0
    **/
    @RequiresPermissions("buychange:planchangereceive:view")
    public String page(Model model, HttpServletRequest request){
        String clientIp = pInventoryInfoEditService.getClientIp(request);
        model.addAttribute("clientIp",clientIp);
        List<VwDictCommon> reasonChangeList = purchasePlanChangeManagementService.getReasonChangeList();
        model.addAttribute("reasonChangeList",reasonChangeList);
        return "buy/buyChangePlanReceive/page";
    }


    @PostMapping("/receive/list")
    @ResponseBody
    /**
     *@name: receiveList
     *@description: 获取变更接收列表
     *@param: [param] 检索参数
     *@returnType: com.zhongwang.mms.common.JsonResult
     *@author: 徐一贺
     *@coddingDate: 2020/8/11 19:54
     *@version: v1.0
    **/
    @RequiresPermissions("buychange:planchangereceive:view")
    public JsonResult receiveList(ShopPlanChangeReceiveModel param){
        startPage();
        List<ShopPlanChangeReceiveModel> list = purchasePlanChangeManagementService.receiveList(param);
        return jsonResult(list);
    }

    @PostMapping("/plan/list")
    @ResponseBody
    /**
     *@name: planList
     *@description: 获取接收变更计划列表
     *@param: [param]
     *@returnType: com.zhongwang.mms.common.JsonResult
     *@author: 徐一贺
     *@coddingDate: 2020/8/12 9:49
     *@version: v1.0
    **/
    @RequiresPermissions("buychange:planchangereceive:view")
    public JsonResult planList(ShopPlanChangeReceiveModel param){
        return success().setData(purchasePlanChangeManagementService.planList(param));
    }

    @PostMapping("/getChangePlan")
    @ResponseBody
    /**
     *@name: getChangePlan
     *@description: 根据rppId获取变更数据
     *@param: [param]
     *@returnType: com.zhongwang.mms.common.JsonResult
     *@author: 徐一贺
     *@coddingDate: 2020/8/12 20:02
     *@version: v1.0
    **/
    public JsonResult getChangePlan(ShopPlanChangeReceiveModel param){
        ShopPlanChangeReceiveModel model = purchasePlanChangeManagementService.getChangePlan(param);
        return JsonResult.success("",model);
    }
    
    @PostMapping("/save/change")
    @ResponseBody
    /**
     *@name: saveChange
     *@description: 保存修改
     *@param: [param]
     *@returnType: com.zhongwang.mms.common.JsonResult
     *@author: 徐一贺
     *@coddingDate: 2020/8/13 8:20
     *@version: v1.0
    */
    @RequiresPermissions("buy:planchangereceive:edit")
    public JsonResult saveChange(@RequestParam(value = "paramStr") String paramStr,@RequestParam("clientIp") String clientIp){
        Gson gson=new Gson();
        List<ShopPlanChangeReceiveModel> pInventoryModelList =  gson.fromJson(paramStr,new TypeToken<List<ShopPlanChangeReceiveModel>>(){}.getType());
        return purchasePlanChangeManagementService.saveChange(pInventoryModelList,clientIp);
    }

    /**
     *@name: revokeChangeStatus
     *@description: 撤销接收变更状态
     *@param: [id]
     *@returnType: com.zhongwang.mms.common.JsonResult
     *@author: 徐一贺
     *@coddingDate: 2020/9/4 15:26
     *@version: v1.0
    **/
    @PostMapping("/revokeChangeStatus")
    @ResponseBody
    @RequiresPermissions("buy:planchangereceive:edit")
    public JsonResult revokeChangeStatus(@RequestParam(value = "id") Integer id){
        return purchasePlanChangeManagementService.revokeChangeStatus(id);
    }
    /**
     *@name: checkChangeMark
     *@description: 检查变更表示
     *@param: [id]
     *@returnType: com.zhongwang.mms.common.JsonResult
     *@author: 徐一贺
     *@coddingDate: 2020/9/4 15:26
     *@version: v1.0
    **/
    @PostMapping("/checkChangeMark")
    @ResponseBody
    @RequiresPermissions("buy:planchangereceive:edit")
    public JsonResult checkChangeMark(@RequestParam(value = "id") Integer id){
        return purchasePlanChangeManagementService.checkChangeMark(id);
    }
    /**
     *@name: planExist
     *@description:  判断计划是否存在C表中
     *@param: [paramStr, clientIp]
     *@returnType: com.zhongwang.mms.common.JsonResult
     *@author: 徐一贺
     *@coddingDate: 2020/9/2 11:51
     *@version: v1.0
    **/
    @PostMapping("/plan/exist")
    @ResponseBody
    @RequiresPermissions("buy:planchangereceive:edit")
    public JsonResult planExist(@RequestParam(value = "id") Integer id){
        return success().setData(purchasePlanChangeManagementService.planExist(id));
    }

    /**********************************************
     * @title: checkEmployIsRecipient
     * @description: 检测该物控员是不是 计划接收者
     * @param:
     * @return:
     * @author: 徐一贺
     * @date: 2020/9/18 14:42
     * @versron: ver 1.0
     **********************************************
     */
    @PostMapping("/checkEmployIsRecipient")
    @ResponseBody
    @RequiresPermissions("buy:planchangereceive:edit")
    public JsonResult checkEmployIsRecipient(@RequestParam("empName") String empName){
        return purchasePlanChangeManagementService.checkEmployIsRecipient(empName);
    }
}
